﻿<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:controls="clr-namespace:Soat.HappyNet.Silverlight.Library.Controls;assembly=Soat.HappyNet.Silverlight.Library"
    xmlns:windowControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"             
    xmlns:regions="clr-namespace:Microsoft.Practices.Composite.Presentation.Regions;assembly=Microsoft.Practices.Composite.Presentation"
    xmlns:cal="clr-namespace:Microsoft.Practices.Composite.Presentation.Commands;assembly=Microsoft.Practices.Composite.Presentation" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" x:Class="Soat.HappyNet.Silverlight.Modules.Production.Views.ProductsListView"
    xmlns:toolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    xmlns:triggers="clr-namespace:Soat.HappyNet.Silverlight.Library.Behaviors.Triggers;assembly=Soat.HappyNet.Silverlight.Library"
    xmlns:actions="clr-namespace:Soat.HappyNet.Silverlight.Library.Behaviors.Actions;assembly=Soat.HappyNet.Silverlight.Library"
    xmlns:behaviors="clr-namespace:Soat.HappyNet.Silverlight.Library.Behaviors;assembly=Soat.HappyNet.Silverlight.Library"
    mc:Ignorable="d">
    <Grid x:Name="LayoutRoot">
        <Grid Margin="0,5,0,0">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition />
            </Grid.RowDefinitions>
            
            <Border Grid.Row="0"
                    HorizontalAlignment="Center"
                    CornerRadius="6"
                    BorderBrush="{StaticResource DefaultBorderBrush}"
                    BorderThickness="1"
                    Background="{StaticResource DiscreteHeaderBrush}"
                    Padding="10,4,10,4">
                <i:Interaction.Behaviors>
                    <behaviors:NullValueVisibilityBehavior ValueBinding="{Binding CategoryName}" />
                </i:Interaction.Behaviors>
                <Grid>
                    <TextBlock Text="{Binding CategoryName}"
                               Style="{StaticResource ProductsTitleStyle}"/>
                </Grid>
            </Border>
            
            <ScrollViewer Style="{StaticResource ScrollViewerStyle}"
                          Grid.Row="1"
                          HorizontalScrollBarVisibility="Disabled">
                <Grid>
                    <ItemsControl x:Name="ProductsListControl"
                                  ItemsSource="{Binding FilteredProducts}"
                                  HorizontalAlignment="Center">
                        <i:Interaction.Behaviors>
                            <behaviors:BoolValueVisibilityBehavior 
                                ValueBinding="{Binding FilteredProducts.Count, Converter={StaticResource IsPositiveConverter}}" />
                        </i:Interaction.Behaviors>
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <toolkit:WrapPanel Orientation="Horizontal"
                                                   VirtualizingStackPanel.VirtualizationMode="Recycling" />
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <ContentControl Content="{Binding View}"
                                                HorizontalContentAlignment="Stretch"
                                                VerticalContentAlignment="Stretch" />
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                    <Grid HorizontalAlignment="Center"
                               VerticalAlignment="Top"
                               Margin="10">
                        <i:Interaction.Behaviors>
                            <behaviors:BoolValueVisibilityBehavior 
                                Negate="True"
                                ValueBinding="{Binding IsBusy}" />
                        </i:Interaction.Behaviors>
                        <TextBlock Text="{Binding Path=Strings.PRODUCTION_NoProduct, Source={StaticResource LocalizedStrings}}"
                               Style="{StaticResource BoldLabelStyle}">
                            <i:Interaction.Behaviors>
                                <behaviors:BoolValueVisibilityBehavior 
                                    Negate="True"
                                    ValueBinding="{Binding FilteredProducts.Count, Converter={StaticResource IsPositiveConverter}}" />
                            </i:Interaction.Behaviors>
                        </TextBlock>
                    </Grid>
                </Grid>
            </ScrollViewer>
        </Grid>

        <controls:Loading IsLoading="{Binding IsBusy}"
                          HorizontalAlignment="Center"
                          VerticalAlignment="Center"/>
    </Grid>
</UserControl>
